package dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

/**
 * @author bohan
 * @create 2017年5月21日
 */
public class ShiroDaoImpl implements ShiroDao{
	private SessionFactory sessionFactory;
	public Session getSession(){
		return sessionFactory.openSession();
	}
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public List runsql(String sql) {
		List list = new ArrayList();
		try
		{
			Session session = getSession();
			Query query = session.createSQLQuery(sql);
			list = query.list();
			session.close();
			return list;
		}catch(Exception e)
		{
			e.printStackTrace();
			return list;
		}
	}
	
}
